package com.kt.delivery.utils;

import com.kt.delivery.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import javax.servlet.http.HttpServletRequest;

@Component
public class LoginHelper {


    @Autowired
    private  RedisTemplate<String,Object> redisTemplate;

    public  Long getUserId(){

        User user = (User) RequestContextHolder.currentRequestAttributes().getAttribute("user", RequestAttributes.SCOPE_REQUEST);

//        //从redis中获取用户信息
//        User user = (User) redisTemplate.opsForValue().get("token:" + token);

        return user.getId();

    }

    public String getOpenId(){
        Object openId = RequestContextHolder.currentRequestAttributes().getAttribute("openId", RequestAttributes.SCOPE_REQUEST);
        return (String) openId;
    }

}
